package com.troyhigh.njrotc.admintrackerold;

public class ChartMaker
{
    //[c][r]
    //doesn't work.
    
    public static void main(String[] args)
    {
        String[] one = {"Someone", "Says", "That", "Hot"};      
        String[] two = {"Pie", "Is", "Very", "Delicious"};
        String[][] fun = {one, two};
        System.out.println(makeChart(fun));
    }
    
    private static String makeChart(String[][] arr)
    {
        String result = "";
        int [] widths = columnWidths(arr);
        for(int i = 0; i < arr.length; i++)
        {
            result += "+";
            for(int h = 0; h < arr[i].length; h++)
            {
                for(int j = 0; j < widths[h]; j++)
                {
                    result += "-";
                }
                result += "-";
            }
           result +="\n";
            
            for(int k = 0; k < arr.length; k++)
            {
                result += "|";
                result += (arr[k][i]);
                for(int l = arr[k][i].length(); l < widths[k]; l++)
                {
                    result += " ";
                }
            }
            result += "|";
            result += "\n";
        }
        result += "+";
        for(int h = 0; h < arr.length; h++)
            {
                for(int j = 0; j < widths[h]; j++)
                {
                    result += "-";
                }
                result += "+";
            }
            result += "\n";
        return result;
    }
    
    private static int widthOfColumn(int row, String[][] arr)
    {
        int max = 0;
        for(int i = 0; i < arr[row].length; i++)
        {
            int wid = arr[row][i].length();
            if(wid > max) 
                max = wid;
        }
        return max;
    }
    
    private static int[] columnWidths(String[][] arr)
    {
        int[] result = new int[longestRow(arr)];
        for(int i = 0; i < longestRow(arr); i++)
        {
            result[i] = widthOfColumn(i, arr);
        }
        return result;
    }
                
    private static int longestRow(String[][] arr)
    {
        int max = 0;
        for(int i = 0; i < arr.length; i++)
        {
           int len = arr[i].length;
           if(len > max)
               max = len;
        }
        return max;
    }
}
